<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:variable name="director_photo">zym.jpg</xsl:variable>
    <xsl:template match="/">
        <html>
            <head>
                <link rel="stylesheet" type="text/css" href="movies.css"/>
            </head>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="/movies">
        <!-- <xsl:call-template name="director">
            <xsl:with-param name="name" select="director/name"/>
            <xsl:with-param name="birthday" select="director/birthday"/>
            <xsl:with-param name="gender" select="director/gender"/>
            <xsl:with-param name="hometown" select="director/hometown"/>
            <xsl:with-param name="imdbNumber" select="director/imdbNumber"/>
            <xsl:with-param name="introductionLink" select="director/introductionLink"/>
        </xsl:call-template> -->
        <xsl:call-template name="moviesByName"/>
        <xsl:call-template name="moviesByType"/>
        <xsl:call-template name="allMovies"/>
    </xsl:template>

    <xsl:template match="/movies/moviesByName" name="moviesByName">
        <div class="moviesByX">
            <xsl:for-each select="/movies/moviesByName/movies">
                <p style="font-weight:bold"><xsl:value-of select="@name"/></p>
                <p>作品数量:<xsl:value-of select="@nums"/></p>
                <xsl:for-each select="title">
                    <xsl:value-of select="."></xsl:value-of><xsl:if test="position()!=last()">, </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </div>
    </xsl:template>

    <xsl:template match="/movies/moviesByType" name="moviesByType">
        <div class="moviesByX">
            <xsl:for-each select="/movies/moviesByType/movies">
                <p style="font-weight:bold"><xsl:value-of select="@name"/></p>
                <xsl:for-each select="title">
                    <xsl:value-of select="."></xsl:value-of><xsl:if test="position()!=last()">, </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </div>
    </xsl:template>


    <xsl:template name="director">
        <xsl:param name="name"/>
        <xsl:param name="hometown"/>
        <xsl:param name="gender"/>
        <xsl:param name="birthday"/>
        <xsl:param name="introductionLink"/>
        <xsl:param name="imdbNumber"/>
        <div class="director">
            <div class="avatar">
                <img>
                    <xsl:attribute name="src">
                        <xsl:value-of select="$director_photo"/>
                    </xsl:attribute>
                    <xsl:attribute name="width">
                        160
                    </xsl:attribute>
                    <xsl:attribute name="height">
                        240
                    </xsl:attribute>
                </img>
            </div>
            <div class="profile">
                <p>姓名:
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="$introductionLink"/>
                        </xsl:attribute>
                        <xsl:value-of select="$name"/>
                    </a>
                </p>
                <p>家乡: <xsl:value-of select="$hometown"/></p>
                <p>性别: <xsl:value-of select="$gender"/></p>
                <p>出生日期: <xsl:value-of select="$birthday"/></p>
                <p>imdb编号: <xsl:value-of select="$imdbNumber"/></p>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="/movies/allMovies" name="allMovies">
        <div class="allMovies">
            <xsl:for-each select="/movies/allMovies/movie">
                <xsl:sort select="doubanRating" order="descending"/>
                <xsl:if test="doubanRating &gt; 7.0">
                    <div class="movie">
                        <p>电影名称:
                            <a>
                                <xsl:attribute name="href">
                                    <xsl:value-of select="link"/>
                                </xsl:attribute>
                                <xsl:value-of select="title"/>
                            </a>
                        </p>
                        <p>排名: <xsl:number value="position()"/></p>
                        <p>豆瓣评分: <xsl:value-of select="doubanRating"/>
                            <xsl:choose>
                                <xsl:when test="doubanRating &gt; 9.0">
                                    (强烈推荐)
                                </xsl:when>
                                <xsl:when test="doubanRating &gt; 7.5">
                                    (推荐)
                                </xsl:when>
                                <xsl:otherwise>
                                    (一般)
                                </xsl:otherwise>
                            </xsl:choose>
                        </p>
                        <p>上映时间: <xsl:value-of select="releaseTime"/></p>
                        <p>Imdb编号: <xsl:value-of select="@imdbId"/></p>
                        <p>电影长度: <xsl:value-of select="lengthOfFilm"/></p>
                        <p>类型:
                            <xsl:for-each select="types/type">
                                <xsl:value-of select="@typeName"/>
                                <xsl:if test="position() != last()">
                                    ,
                                </xsl:if>
                            </xsl:for-each>
                        </p>
                        <p>主演:
                            <xsl:choose>
                                <xsl:when test="count(leadingActors) = 0">
                                    无
                                </xsl:when>
                                <xsl:when test="count(leadingActors/leadingActor) = 0">
                                    无
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:for-each select="leadingActors/leadingActor">
                                        <a>
                                            <xsl:attribute name="href">
                                                <xsl:value-of select="@link"/>
                                            </xsl:attribute>
                                            <xsl:value-of select="."/>
                                        </a>
                                        (<xsl:value-of select="@gender"/>)
                                    </xsl:for-each>
                                </xsl:otherwise>
                            </xsl:choose>
                        </p>
                        <p>编剧:
                            <xsl:choose>
                                <xsl:when test="count(playwrights) = 0">
                                    无
                                </xsl:when>
                                <xsl:when test="count(playwrights/playwright) = 0">
                                    无
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:for-each select="playwrights/playwright">
                                        <a>
                                            <xsl:attribute name="href">
                                                <xsl:value-of select="@link"/>
                                            </xsl:attribute>
                                            <xsl:value-of select="."/>
                                        </a>
                                        (<xsl:value-of select="@gender"/>)
                                    </xsl:for-each>
                                </xsl:otherwise>
                            </xsl:choose>
                        </p>
                    </div>
                </xsl:if>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>